package com.bw.module_home.adapter

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.bw.module_home.model.entity.SimpleTypeEntity
import com.bw.module_home.ui.SimpleTypeFragment

/**
 * @Author : ZhouZiYao
 * @Time : On 2023/11/22 19:37
 * @Description :
 */
class HomePagerAdapter(private val titles:MutableList<SimpleTypeEntity>, private val fm: FragmentManager):
    FragmentStatePagerAdapter(fm) {
    private val list:MutableList<Fragment> = mutableListOf()
    //根据titles创建对应的fragment
    init {
        titles.forEach { title ->
            val simpleTypeFragment = SimpleTypeFragment()
            //创建fragment将channelId传递过去
            val bundle= Bundle()
            bundle.putString("id",title.channelid)
            simpleTypeFragment.arguments=bundle
            list += simpleTypeFragment
        }
    }




    override fun getCount(): Int {
        return titles.size
    }

    override fun getItem(position: Int): Fragment {
        return list[position]
    }
    override fun getPageTitle(position: Int): CharSequence? {
        return titles[position].typename
    }
}